<%@ page import="com.scalar.chiptrack.utils.ConfigManager, java.util.Calendar"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>

<chiptrack:checkLogon sourcePage="/financeReport.do?action=releaseLots" />
<%String chipTracContext = "/" + ConfigManager.getChipTracContext();%>

<%
    String processType      = request.getParameter("processType");
    String productId        = request.getParameter("product");

    if( processType == null || ( processType != null && processType.trim().length() == 0 ) )
    {
        processType = "0";
    }

    if( productId == null || ( productId != null && productId.trim().length() == 0 ) )
    {
        productId = "0";
    }
%>

<HTML><HEAD><TITLE>Scalarsoft - ChipTrac</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type="text/css" rel=stylesheet>
<SCRIPT language="JavaScript" src="<%=chipTracContext%>/jsp/includes/scripts/functions.js"></SCRIPT>
<SCRIPT language="JavaScript" src="<%=chipTracContext%>/jsp/includes/scripts/validations.js"></SCRIPT>

<SCRIPT language="JavaScript">

var dateElement = "";
function openCalendar(dateValue)
{
    dateElement = dateValue;
    newWindow = window.open('<%=chipTracContext%>/jsp/includes/calendar.html','optionsPopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=no,width=180,height=440,resizable=no');
    newWindow.moveTo(550,180);
    newWindow.focus();
}
function assignDate(passedValue)
{
    dateElement.value=passedValue;
    window.focus();
}

function getProductsForProcess()
{
    document.lotreleaseReport.action="<%=chipTracContext%>/financeReport.do?action=releaseLots&processType="+document.lotreleaseReport.processType.value;
    document.lotreleaseReport.submit();
}

function validateFromAndToDates()
{
    var formdoc = document.lotreleaseReport;
    errMsg = '';

    var pa	= document.getElementById("errors")

    if(chkDate(formdoc.datefrom.value,'From-Date','N') == false)
    {
        pa.innerHTML = errMsg;
        formdoc.datefrom.focus();
        return false;
    }

    if(chkDate(formdoc.dateto.value,'To-Date','N') == false)
    {
        pa.innerHTML = errMsg;
        formdoc.dateto.focus();
        return false;
    }

    if(formdoc.datefrom.value!='' && formdoc.dateto.value!='')
    {
        if (!validateDateOut(formatDateAsMMDDYYYY(formdoc.datefrom.value),formatDateAsMMDDYYYY(formdoc.dateto.value)))
        {
            pa.innerHTML = "To Date cannot be less than From Date";
            formdoc.dateto.focus();
            return false;
        }
    }
    return true;
}

function dateRange()
{
    var d = new Date();
    var day = d.getDate();
    var month = d.getMonth()+1;
    var year = d.getFullYear();
    var hour = d.getHours();
    var min = d.getMinutes();
    var sec = d.getSeconds();

    var reportName = document.lotreleaseReport.reportname.value;

    var defaultPrompt = day+"/"+month+"/"+year+":"+hour+":"+min+":"+sec;

    var success;
    success = true;
    success = validateFromAndToDates();
    if(success == false)
    {
       return false;
    }
   	var pa	= document.getElementById("errors")
	pa.innerHTML = errMsg;
	if (document.lotreleaseReport.processType.value == '0' || document.lotreleaseReport.processType.value == null)
	{
		pa.innerHTML = "<li> Please select Process Type ";
        return false;
	}

    var element = document.lotreleaseReport.products;
    var productName = "";
    var count = 0;
    for( var i = 0 ; i < element.length; i++ )
    {
        if (element.options[i].selected)
        {
            count++;
            if ( productName != '' )
            {
              productName = productName+","+element.options[i].value;
            }
            else
            {
                productName = element.options[i].value;
                if( element.options[i].value == '0' )
                {
                    break;
                }
            }
        }
    }
    if ( productName == '')
    {
        productName = "0";
    }
    if( count > 10)
    {
        pa.innerHTML = "<li>Please select upto 10 products only";
		return false;
    }
    else
    {
        document.lotreleaseReport.prompt0.value = productName;
    }

    if (document.lotreleaseReport.processType.value == '')
        document.lotreleaseReport.prompt1.value='0';
    else
        document.lotreleaseReport.prompt1.value = document.lotreleaseReport.processType.value;

    if (document.lotreleaseReport.datefrom.value =='')
        document.lotreleaseReport.prompt2.value='0';
    else
        document.lotreleaseReport.prompt2.value = document.lotreleaseReport.datefrom.value;

    if (document.lotreleaseReport.dateto.value == '')
        document.lotreleaseReport.prompt3.value='0';
    else
        document.lotreleaseReport.prompt3.value = document.lotreleaseReport.dateto.value;

    var vendorElement = document.lotreleaseReport.fromvendor;
    var vendor = "";
    var vendorcount = 0;
    for( var i = 0 ; i < vendorElement.length; i++ )
    {
        if ( vendorElement.options[i].selected )
        {
            vendorcount++;
            if ( vendor != '')
            {
                vendor = vendor+","+vendorElement.options[i].value;
            }
            else
            {
                vendor = vendorElement.options[i].value;
                if( vendorElement.options[i].value == '0' )
                {
                    break;
                }
            }
        }
    }
    if ( vendor == '')
    {
        vendor = "0";
    }
    if( vendorcount > 10)
    {
        pa.innerHTML = "<li>Please select upto 10 Vendors only";
        return false;
    }
    else
    {
        document.lotreleaseReport.prompt4.value = vendor;
    }

    var statusElement = document.lotreleaseReport.status;
    var status = "";
    var statuscount = 0;
    for( var i = 0 ; i < statusElement.length; i++ )
    {
        if (statusElement.options[i].selected)
        {
            statuscount++;
            if ( status != '' )
            {
                status = status + "," + statusElement.options[i].value;
            }
            else
            {
               status = statusElement.options[i].value;
               if( statusElement.options[i].value == '0' )
                {
                    break;
                }
            }
        }
    }
    if ( status == '')
    {
        status = "0";
    }
    if( statuscount > 10)
    {
        pa.innerHTML = "<li>Please select upto 10 Statuses only";
        return false;
    }
    else
    {
        document.lotreleaseReport.prompt5.value = status;
    }

    document.lotreleaseReport.prompt6.value =defaultPrompt;

    if(document.lotreleaseReport.processType.value == 'Class Store')
    {
         if (document.lotreleaseReport.customer.value == '')
         {
            document.lotreleaseReport.prompt7.value='0';
         }
         else
         {
            document.lotreleaseReport.prompt7.value = document.lotreleaseReport.customer.value;
         }
    }
    else
    {
       document.lotreleaseReport.prompt7.value ='';
    }

    document.lotreleaseReport.prompt8.value ='';
    document.lotreleaseReport.prompt9.value ='';
    document.lotreleaseReport.prompt10.value='';

	if(document.lotreleaseReport.processType.value == 'SORT'  )
	{
   		 document.lotreleaseReport.action="<%=chipTracContext%>/jsp/report.jsp?nameReport=Operations/RELEASE_REPORT.rpt";
    }
    else if (document.lotreleaseReport.processType.value == 'Assembly')
    {
    	document.lotreleaseReport.action="<%=chipTracContext%>/jsp/report.jsp?nameReport=Operations/Release_Report_Assembly.rpt";
    }
    
}

function loadProducts()
{
	document.lotreleaseReport.action="<%=chipTracContext%>/financeReport.do?action=releaseLots";
	document.lotreleaseReport.submit();
}


function clearErrors()
{
    var pa=document.getElementById("errors");
    pa.innerHTML = "";
}

</script>
</HEAD>
<BODY bgColor="#ffffff" leftMargin=0 topMargin=0 marginheight="0" marginwidth="0">

<!-- Top Header Start-->
<%@ include file="/jsp/includes/header.jsp" %>
<!-- Top Header End-->

<TABLE cellSpacing=0 cellPadding=0 width="100%" border="0">
    <TR>
        <td width='180' valign='top' background='<%=chipTracContext%>/jsp/includes/images/left_red_bg.gif'>
            <!-- Side Navigation start -->
            <%@ include file="/jsp/operations/reports_side_menu.jsp" %>
            <!-- end of the side navigations -->
        </td>
        <TD bgcolor="#ffffff"><IMG height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=8></TD>
        <TD bgcolor="#ffffff"><IMG height=480 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=2></TD>
        <TD bgcolor="#ffffff">
            <form name="lotreleaseReport" method="post">
            <input type="hidden" name="prompt0">
            <input type="hidden" name="prompt1">
            <input type="hidden" name="prompt2">
            <input type="hidden" name="prompt3">
            <input type="hidden" name="prompt4">
            <input type="hidden" name="prompt5">
            <input type="hidden" name="prompt6">
            <input type="hidden" name="prompt7">
            <input type="hidden" name="prompt8">
            <input type="hidden" name="prompt9">
            <input type="hidden" name="prompt10">
            <input type="hidden" name="reportname" value="<%=request.getParameter("reportname")%>">
        </TD>
        <TD valign="top" width="100%">
            <table border="1" width="100%" align="left">
                <tr><td colspan="6" width="100%"><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10></td></tr>
                <tr><td colspan="6" width="100%"><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10></td></tr>
                <tr><td colspan="6" width="100%"><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10></td></tr>
                <tr>
                    <TD width="100%" COLSPAN="6">
                        <TABLE width="100%" align=right border="1">
                            <TR>
                                <TD width="15%" colspan="2">&nbsp;</TD>
                                <TD width="85%" colspan="4"class="NArialW" align = "center">Release Lot Report&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
                                <!--<TD width="30%">&nbsp;</TD>-->
                            </TR>
                        </TABLE>
                    </TD>
                </tr>
                <tr><td colspan="6" width="100%"><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10></td></tr>
                <tr>
                    <td width="15%" colspan="2">&nbsp;</td>
                    <td width="85%" colspan="4" align="left">
                        <b><font face="Verdana" size="-5" align="center" color="#ff0000" id="errors"></font></b>&nbsp;
                    </td>
                </tr>
                <TR>
                    <TD width="5%">&nbsp;</TD>
                    <TD width="15%" valign="top" class=NArialL> Process Type</TD>
                    <TD width="25%" valign="top" class=NArialL>
                       <select size="1" name="processType" class="txfield"  onChange="getProductsForProcess()">
                           <option value="0">Select Process Type</option>
                            <logic:iterate id="processList" name="processList" >
                                <logic:equal name="processList" property="value" value="<%=processType%>"><option value="<bean:write name="processList" property="value"/>" selected><bean:write name="processList" property="label"/></option></logic:equal>
                                <logic:notEqual name="processList" property="value" value="<%=processType%>"><option value="<bean:write name="processList" property="value"/>"><bean:write name="processList" property="label"/></option></logic:notEqual>
                            </logic:iterate>
                       </select>
                    </TD>
                    <TD width="5%">&nbsp;</TD>
                    <TD width="20%" valign="top" class=NArialL>Product Name<br>(<bean:message key = "label.mfgPartNumber" />)</TD>
                    <TD width="30%" valign="top" class=NArialL>
                        <select size="5" name="products" class="txfield" multiple="true">
                            <option value="0" selected>All Products</option>
                            <logic:iterate id="mktgPartNumberSelectList" name="productList" >
                                <logic:notEqual name="mktgPartNumberSelectList" value="null">
                                    <option value="<bean:write name="mktgPartNumberSelectList" property="value"/>" >
                                        <bean:write name="mktgPartNumberSelectList" property="label"/>
                                    </option>
                                </logic:notEqual>
                            </logic:iterate>
                        </select>
                    </TD>
                </TR>

                <TR>
                   <TD width="5%">&nbsp;</TD>
                    <TD width="15%" valign="top" class=NArialL>Vendor</TD>
                    <TD width="25%" valign="top" class=NArialL>
                        <select size="5" name="fromvendor" class="txfield" multiple="true" >
                            <option value="0" selected>All Vendors</option>
                            <logic:iterate id="vendorList" name="vendorList" >
                                <logic:notEqual name="vendorList" value="null">
                                    <option value ="<bean:write name="vendorList" property="value"/>" >
                                        <bean:write name="vendorList" property="label"/>
                                    </option>
                                </logic:notEqual>
                            </logic:iterate>
                        </select>
                    </TD>
                    <TD width="5%">&nbsp;</TD>
                    <TD width="20%" valign="top" class=NArialL>Status</TD>
                    <TD width="30%" valign="top" class=NArialL>
                        <select size="5" name="status" class="txfield" multiple="true">
                            <option value="0" selected>All Status</option>
                            <logic:iterate id="statusList" name="statusList" >
                                <logic:notEqual name="statusList" value="null">
                                    <option value ="<bean:write name="statusList" property="value"/>">
                                        <bean:write name="statusList" property="label"/>
                                    </option>
                                </logic:notEqual>
                            </logic:iterate>
                        </select>
                    </TD>
                </TR>

                <tr><td colspan="6" width="100%"><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10></td></tr>
                <TR>
                    <TD width="5%">&nbsp;</TD>
                    <TD width="15%" class=NArialL>From-Date</TD>
                    <TD width="25%" class=NArialL>
                        <input type="text" name="datefrom" size="12" class="txfield">&nbsp;
                        <a href="javascript:openCalendar(document.lotreleaseReport.datefrom)"onmouseover="window.status='Click to Select From Date';return true"onmouseout="window.status='';return true"title="Click here to Select From Date">
                        <img border="0" src="<%=chipTracContext%>/jsp/includes/images/date_selector.gif" height=18 width=18></a>
                    </TD>
                    <TD width="5%">&nbsp;</TD>
                    <TD width="20%" class=NArialL>To-Date</TD>
                    <TD width="30%" class=NArialL>
                        <input type="text" name="dateto" size="12" class="txfield">&nbsp;
                        <a href="javascript:openCalendar(document.lotreleaseReport.dateto)"onmouseover="window.status='Click to Select To Date';return true"onmouseout="window.status='';return true"title="Click here to Select To Date">
                        <img border="0" src="<%=chipTracContext%>/jsp/includes/images/date_selector.gif" height=18 width=18></a>

                    </TD>  
                </TR>
                <tr><td colspan="6"><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=20>&nbsp;</td></tr>
                <tr>
                    <td width="30%" colspan="2"><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=20>&nbsp;</td>
                    <td width="70%"  colspan="4" align="center">
                        <input type="image" onClick="javascript:return dateRange();"  border="0" src="<%=chipTracContext%>/jsp/includes/images/submit.gif" width="53" height="17" onmouseover="window.status='Click to Generate Report';return true"onmouseout="window.status='';return true"title="Click here to Generate Report">
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <a href="javascript:document.lotreleaseReport.reset();"><img src="<%=chipTracContext%>/jsp/includes/images/reset.gif" border='0' onmouseover="window.status='Click to Reset';return true" onmouseout="window.status='';return true"title="Click here to Reset"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    </td>
                </tr>
            </table>
            <BR><BR><BR>
            </form>
        </TD>
        <TD bgcolor="#ffffff"><IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=1></TD>
    </TR>
</TABLE>
<!-- Footer starts here -->
<%@ include file="/jsp/includes/footer.jsp" %>
<!-- footer end here -->
</BODY>
</HTML>
